//
//  UIBarButtonItem+WENExtension.m
//  仿百思不得姐
//
//  Created by wen on 2018/2/9.
//  Copyright © 2018年 wen. All rights reserved.
//

#import "UIBarButtonItem+WENExtension.h"

@implementation UIBarButtonItem (WENExtension)

+ (instancetype)itemWithImageNamed:(NSString *)imageName target:(id)target action:(SEL)action {

    //设置左边按钮
    UIButton *btn = [[UIButton alloc] init];
    [btn setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
    //拼接字符串,获取高亮状态图片名称
    NSString *heightLightImageName = [imageName stringByAppendingString:@"-click"];
    [btn setImage:[UIImage imageNamed:heightLightImageName] forState:UIControlStateHighlighted];
    btn.bounds = CGRectMake(0, 0, btn.currentImage.size.width, btn.currentImage.size.height);
    [btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    
    return [[UIBarButtonItem alloc] initWithCustomView:btn];

}

+ (instancetype)backItemWithImageNamed:(NSString *)imageName title:(NSString *)title target:(id)target action:(SEL)action {

    //设置左边按钮
    UIButton *btn = [[UIButton alloc] init];
    
    //给按钮设置title
    [btn setTitle:@"返回" forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted];
    
    //设置按钮的内容位置
        //内容向左对齐
    btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    [btn setContentEdgeInsets:UIEdgeInsetsMake(0, -10, 0, 0)];
    
    
    [btn setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
    //拼接字符串,获取高亮状态图片名称
    NSString *heightLightImageName = [imageName stringByAppendingString:@"-click"];
    [btn setImage:[UIImage imageNamed:heightLightImageName] forState:UIControlStateHighlighted];
    btn.bounds = CGRectMake(0, 0, btn.currentImage.size.width + 80, btn.currentImage.size.height);
    [btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    
    return [[UIBarButtonItem alloc] initWithCustomView:btn];

}



@end
